<div class="layui-fluid layui-anim website-anim-up" id="website-home" lay-title="系统首页">
    <div class="layui-row layui-col-space8 website-container">
        <div class="layui-col-md10 layui-col-sm10 layui-col-xs10">
            <div class="layui-card" id="client-user-info">
                <div class="layui-card-header"><i class="layui-icon layui-icon-friends"></i>&nbsp;基本信息</div>
                <div class="layui-card-body">

                    <!-- 基本信息-->
                    <div class="layui-row">
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">姓名：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.name :''}]]
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">学科分类：</div>
                            <div id="subjectTypeCode" class="layui-col-xs7 layui-col-sm7 layui-col-md7"></div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">手机：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.mobile :''}]]
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">座机：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.phone :''}]]
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">所属单位：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.company :''}]]
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">通讯地址：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.address :''}]]
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">证件号：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.identityId :''}]]
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">邮箱：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7"> [[${expert != null ?
                                expert.email :''}]]
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">


                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">职称：</div>
                            <div id="titleTypeCode" class="layui-col-xs7 layui-col-sm7 layui-col-md7"></div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">理论与实务专家：</div>
                            <div id="featureTypeCode" class="layui-col-xs7 layui-col-sm7 layui-col-md7">
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">京内与京外专家：</div>
                            <div id="districtTypeCode" class="layui-col-xs7 layui-col-sm7 layui-col-md7">
                            </div>
                        </div>
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">银行账号：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7">[[${expert != null ?
                                expert.accountId :''}]]
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs6 layui-col-sm6 layui-col-md3">
                            <div class="layui-col-xs5 layui-col-sm5 layui-col-md5">开户行：</div>
                            <div class="layui-col-xs7 layui-col-sm7 layui-col-md7">[[${expert != null ?
                                expert.bankName :''}]]
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-xs12 layui-col-sm12 layui-col-md5 layui-col-md-offset7">
                            <div class="info-option">
                                <button id="updateExpertInfo" class="layui-btn layui-btn-normal layui-btn-sm">修改基本信息
                                </button>
                                <button id="updateExpertEmail" class="layui-btn layui-btn-normal layui-btn-sm">修改邮箱号
                                </button>
                                <button id="updateExpertPassword" class="layui-btn layui-btn-normal layui-btn-sm">
                                    修改登录密码
                                </button>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header"><i class="layui-icon layui-icon-file"></i>&nbsp;指南评审</div>
                <div class="layui-card-body website-table-full" id="client-guide-report">
                    <form class="layui-form layui-table-form" lay-filter="review-guide-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">年份</label>
                                        <div class="layui-input-inline">
                                            <input type="text" class="layui-input" id="topicPlanYearSearch" readonly
                                                   name="year">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="guide-query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="expertGuideTable" lay-data="{id: 'expertGuideTable'}"></table>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header"><i class="layui-icon layui-icon-tabs"></i>&nbsp;课题评审</div>
                <div class="layui-card-body website-table-full" id="client-review-apply">
                    <form class="layui-form layui-table-form" lay-filter="review-apply-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md12">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">课题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode" lay-filter="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${subjectTypeCode}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">审核状态</label>
                                        <div class="layui-input-inline">
                                            <select name="statusTypeCode" lay-filter="statusTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${topicStatusCode}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-col-md-offset10 layui-col-md2 layui-col-sm2 layui-col-xs2 table-action-area">
                                        <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                             id="query">
                                            查询
                                        </div>
                                        <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                             id="reset-review">
                                            重置
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="classReviewTable" lay-data="{id: 'classReviewTable'}"></table>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header"><i class="layui-icon layui-icon-file"></i>&nbsp;举报审查</div>
                <div class="layui-card-body website-table-full" id="client-review-report">
                    <table lay-filter="expertCheckTable" lay-data="{id: 'expertCheckTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--申报人表操作栏 -->
<script type="text/html" id="apply-option">
    <a lay-event="detail" class="website-green">查看</a>
    <!--    -->
    {{# if( d.statusCode === 'expert' && !d.isSubmit){ }}
    <a lay-event="review" class="website-orange">评审</a>
    <a lay-event="submit">提交</a>
    {{#  } }}
</script>

<!--表格中的操作栏-->
<script type="text/html" id="expertCheck-option">
    <a lay-event="detail" class="website-blue">详情</a>
    {{# if(d.report.isExpertReal===null ){}}
    <a lay-event="real" class="website-green">属实</a>
    <a lay-event="noReal" class="website-blue">不属实</a>
    {{#  } }}
</script>

<!--表格中的操作栏-->
<script type="text/html" id="guide-option">

    <a lay-event="detail" class="website-green">详情</a>
    {{# if( !d.reviewFinished){}}
    <a lay-event="review" class="website-blue">评审</a>
    {{#  } }}
</script>
<script type="text/html" id="leader-name-type">
    {{#  if(d.leader){ }}
    <span>{{ d.leader.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="company-name-type">
    {{#  if(d.leader){ }}
    <span>{{ d.leader.company }}</span>
    {{#  } }}
</script>
<script type="text/html" id="subject-name-type">
    {{#
    let dictSubjectTypeCode=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dictSubjectTypeCode){ }}
    <span>{{ dictSubjectTypeCode.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="research-name-type">
    {{#
    let dict=layui.dict.getByCode(d.researchTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="achievement-form-name-type">
    {{#

    let dictList=layui.dict.getByCodes(d.achievementFormTypeCode ? d.achievementFormTypeCode.split(',') : '');
    }}
    <span>
    {{# layui.each(dictList,function(index,item) { }}
    {{ item.name }}&nbsp;
    {{#  }); }}
    </span>
</script>
<script type="text/html" id="publish-unit">
    <span>中国法学会</span>
</script>
<script type="text/html" id="finishType">
    {{#  if(d.reviewFinished){ }}
    <span style="color: green"> 是 </span>
    {{#  } else { }}
    <span style="color: red"> 否 </span>
    {{#  } }}
</script>
<!--表格中字典的显示-->
<script type="text/html" id="levelType">
    {{#
    let dict=layui.dict.getByCode(d.levelTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  }else { }}
    <span>未定级</span>
    {{#  } }}
</script>


<script data-th-inline="javascript" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'website', 'dict', 'clientModules'], function () {
        let $ = layui.jquery,
            laydate = layui.laydate,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            client = layui.clientModules,


            $view = $('#website-home'),
            $clientReview = $('#client-review-apply'),
            $reportView = $('#client-review-report'),
            $guideView = $('#client-guide-report'),
            $query = $view.find('#query'),
            $queryReport = $('#query-report'),
            $reset = $view.find('#reset-review'),
            $resetReport = $('#reset-report'),
            $searchForm = $view.find('form'),
            $reportForm = $reportView.find('#expertCheck-table-form'),
            $guideForm = $guideView.find('#review-guide-form'),
            $guideQuery = $guideView.find('#guide-query'),
            $updateExpertInfo = $('#updateExpertInfo'),
            $updateExpertPassword = $('#updateExpertPassword'),
            $updateExpertEmail = $('#updateExpertEmail'),


            sortObject = {field: 'isSubmit', type: null},
            sortGuideObject = {field: 'reviewFinished', type: null},
            tableReviewIns,
            tableReportIns,
            tableGuideIns,
            expert = [[${expert}]],
            expertId = expert.expertId
        ;
        // 重新渲染 form否则不会显示下拉¬框
        form.render();
        // 渲染表格
        initReviewTable();
        initReportTable();
        initGuideTable();

        function initReviewTable() {
            tableReviewIns = website.table.init({
                elem: $clientReview.find('table'),
                id: 'classReviewTable',
                url: ctx + 'review/expert/list',
                cols: [
                    [
                        {type: 'numbers', title: '序号'},
                        {field: 'name', title: '课题名称', minWidth: 150},
                        {
                            title: '选题名称', templet: function (d) {
                                if (d) return d.topicName;
                            }
                        },
                        {field: 'topicCode', title: '指南序号'},
                        {templet: '#subject-name-type', title: '学科分类'},
                        {templet: '#research-name-type', title: '研究类型'},
                        {templet: '#achievement-form-name-type', title: '成果形式', minWidth: 180},
                        {templet: '#status-name-type', title: '审核状态'},
                        {title: '操作', toolbar: '#apply-option', minWidth: 180}
                    ]
                ]
            });
        }

        table.on('tool(classReviewTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                // 查看详情
                website.navigate("/expert/classReviewDetail/" + data.declareId + '/' + data.reviewId)
            }
            if (layEvent === 'review') {

                website.navigate('/expert/addReview/' + data.declareId + '/' + data.reviewId)
                // 评审
            }
            if (layEvent === 'submit') {
                website.modal.confirm('提交', '确定提交该课题？', function () {
                    // review/{declareId}/commit
                    website.post(ctx + 'review/' + data.reviewId + '/commit', null, function () {
                        //  update
                        $('#website-home').find('#query').click();
                        website.alert.success('提交信息成功');
                        layer.closeAll()
                    });
                });
            }

        });

        function getQueryParams() {
            let params = $searchForm.serializeJson();
            return params;
        }

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableReviewIns.reload({where: params, page: {curr: 1}});
        });
        $reset.on('click', function () {
            $searchForm[0].reset();
            tableReviewIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        function deleteApply(data) {
            website.get(ctx + 'declareTopic/delete?declareId=' + data, null, function () {
                website.alert.success('删除信息成功');
                $query.click();
            });
        }

        // 这个拟立项公告里的拟立项课题
        function initReportTable() {
            tableReportIns = website.table.init({
                elem: $reportView.find('table'),
                id: 'expertCheckTable',
                url: ctx + 'biz/report/expert/list',
                cols: [
                    [
                        {type: 'numbers', title: '序号'},
                        {field: 'name', title: '课题名称', minWidth: 100},
                        {
                            title: '选题名称', minWidth: 100, templet: function (d) {
                                return d.topic.topicName;
                            }
                        },
                        {field: 'topicCode', title: '指南序号', minWidth: 100},
                        {field: 'leaderName', title: '主持人', minWidth: 100},
                        {title: '定级', templet: '#levelType', minWidth: 100},
                        {title: '操作', toolbar: '#expertCheck-option', minWidth: 200}
                    ]
                ]
            });
        }


        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(expertCheckTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                website.modal.view('详情', 'biz/report/expertCheckDetail/' + data.report.reportId, {
                    area: $(window).width() <= 750 ? '95%' : '50%'
                });
            }
            if (layEvent === 'real') {
                website.modal.confirm('确定信息', '确定标记该举报信息属实？', function () {
                    website.post(ctx + 'biz/report/update/' + data.report.reportId, {isExpertReal: true}, function () {
                        layer.closeAll();
                        website.alert.success('标记完成');
                        window.location.reload();
                    });
                });
            }
            if (layEvent === 'noReal') {
                layer.open({
                    type: 1
                    , title: '不属实原因' //不显示标题栏
                    , shade: 0.4
                    , area: $(window).width() <= 750 ? '80%' : '40%'
                    , id: 'LAY_layuinoreal' //设定一个id，防止重复弹出
                    , btn: ['提交', '关闭']
                    , btnAlign: 'c'
                    , zIndex: layer.zIndex
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div class="layui-row" style="margin-top: 20px; margin-right: 20px;">' +
                        '                <div class="layui-col-md12">' +
                        '                    <label class="layui-form-label">不属实原因：</label>' +
                        '                    <div class="layui-input-block">' +
                        '                        <textarea id="checkResult" placeholder="请输入不属实原因" class="layui-textarea"' +
                        '                                  rows="3"></textarea>' +
                        '                    </div>' +
                        '                </div>' +
                        '            </div>'
                    , yes: function (index, layero) {
                        let checkResult = layero.find('#checkResult').val();
                        if (!checkResult) {
                            website.alert.error('请输入不属实原因');
                            return false;
                        }
                        website.post(ctx + 'biz/report/update/' + data.report.reportId, {
                            isExpertReal: false,
                            expertReason: checkResult
                        }, function () {
                            layer.closeAll();
                            website.alert.success('标记完成');
                            window.location.reload();
                        });
                    }
                });
            }
        });


        /**
         * 表格的排序点击
         **/
        table.on('sort(expertCheckTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getExpertCheckQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $queryReport.on('click', function () {
            let params = $.extend(getExpertCheckQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getExpertCheckQueryParams() {
            let params = $reportForm.serializeJson();
            return params;
        }

        initExpert();

        function initExpert() {
            if (expert) {
                $("#subjectTypeCode").text(expert.subjectTypeCode ? layui.dict.getByCode(expert.subjectTypeCode).name : '');
                $("#featureTypeCode").text(expert.featureTypeCode ? layui.dict.getByCode(expert.featureTypeCode).name : '');
                // $("#titleTypeCode").text(expert.titleTypeCode ? layui.dict.getByCode(expert.titleTypeCode).name : '');
                $("#districtTypeCode").text(expert.districtTypeCode ? layui.dict.getByCode(expert.districtTypeCode).name : '');
            }
        }

        $updateExpertInfo.on('click', function () {
            website.modal.open('修改专家', 'system/expert/update/' + expert.expertId, {
                area: $(window).width() <= 750 ? '90%' : '50%',
                offset: '30px',
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    $('#expert-update').find('#submit').trigger('click');
                },
                btn2: function () {
                    layer.closeAll();
                },
                end: function () {
                    window.location.reload();
                }
            });
        });

        $updateExpertEmail.on('click', function () {
            client.updateEmail(ctx);
        });


        $updateExpertPassword.on('click', function () {
                client.updatePassword(ctx)
            }
        );


        // 这个拟立项公告里的拟立项课题
        function initGuideTable() {
            tableGuideIns = website.table.init({
                elem: $guideView.find('table'),
                id: 'expertGuideTable',
                url: ctx + 'expert/guide/review/list',
                where: {expertId: expertId},
                cols: [
                    [
                        {type: 'numbers', title: '序号'},
                        {field: 'year', title: '年份'},
                        {title: '发布单位', templet: '#publish-unit'},
                        {templet: '#finishType', title: '评审完成'},
                        {title: '操作', toolbar: '#guide-option', minWidth: 200}
                    ]
                ]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getExpertGuideQueryParams() {
            let params = $guideForm.serializeJson();
            return params;
        }

        /**
         * 表格的排序点击
         **/
        table.on('sort(expertGuideTable)', function (obj) {
            sortObject = obj;
            tableGuideIns.reload({
                initSort: obj,
                where: $.extend(getExpertGuideQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        table.on('tool(expertGuideTable)', function (obj) {
            let data = obj.data,
                year = data.year,
                distributionRecordId = data.distributionRecordId
            layEvent = obj.event;
            if (layEvent === 'review') {
                // 查看详情
                website.navigate("/expert/annualReview/" + distributionRecordId + "/" + year)
            }
            if (layEvent === 'detail') {
                // 查看详情
                website.navigate("/expert/annualReview/" + distributionRecordId + "/" + year)
            }


        });
        $query.on('click', function () {
            var params = $.extend(getExpertGuideQueryParams(), {
                field: sortGuideObject.field,
                order: sortGuideObject.type
            });
            tableIns.reload({where: params, page: {curr: 1}});
        });

    })
</script>